package cn.northsea.service.impl;

import cn.northsea.mapper.LogisticsMapper;
import cn.northsea.pojo.*;

import cn.northsea.service.LogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


@Service

public class LogisticsServiceImpl implements LogisticsService {
    @Autowired
    private LogisticsMapper logisticsMapper;
    @Override
    public List<LogisticsVo> logistics(String likename) {
        return logisticsMapper.logistics(likename);
    }

    @Override
    public void updateStatu(Integer logisticsId, Integer number) {
        Date date = new Date(System.currentTimeMillis());
         logisticsMapper.updateStatu(logisticsId,number,date);
        int proid= logisticsMapper.seleOrder(logisticsId);
         if (number==1)//已发货
         {
             logisticsMapper.UpdateOrderStatu(proid,3);
         }else if (number==2){//已签收
             logisticsMapper.UpdateOrderStatu(proid,4);
         }
    }

    @Override
    public void updateStatuArr(String[] ids) {
        logisticsMapper.updateStatuArr(ids);
    }

    @Override
    public LogisticsVo tanchuang(Integer id) {
        return logisticsMapper.tanchuang(id);
    }

    @Override
    public List<TransportPersonnel> driver() {
        return logisticsMapper.driver();
    }

    @Override
    public List<LogisticsVo> findAll3() {

            return logisticsMapper.findAll3();
    }

    @Override
    public void updateLogistics(LogisticsVo logisticsVo) {
        Logistics logistics = new Logistics(logisticsVo);
        logisticsMapper.updateLogistics(logistics);
    }

    @Override
    public List<Order> Order(String likename) {

        return logisticsMapper.Order(likename);
    }

    @Override
    public OrderVo generate(Integer id) {
        OrderVo orderVo = new OrderVo();
        orderVo.setOrderId(id);
        orderVo.setUserUsername(logisticsMapper.selectUsername(id));
        Order order=logisticsMapper.selectRessPhone(id);
        orderVo.setOrderAddress(order.getOrderAddress());
        orderVo.setOrderUphone(order.getOrderUphone());
        orderVo.setWarehouseAddress(logisticsMapper.seleAddware(id));
        orderVo.setUserPhone(logisticsMapper.slelctWarePhonr());
        orderVo.setUsername(logisticsMapper.sleectname());
        Product product=logisticsMapper.selectProduct(id);
        orderVo.setErpProductvo(product.getProductName()+":"+product.getProductSize());
        return orderVo;
    }

    @Override
    @Transactional
    public void addlogistics(LogisticsVo logisticsVo) {
        Logistics logistics = new Logistics(logisticsVo);
        logisticsMapper.addlogistics(logistics);
        logisticsMapper.UpdateOrderStatu(logistics.getOrderId(),2);
    }


}
